package com.ruoyi.service.impl;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.domain.BaseBehaviormanagementLog;
import com.ruoyi.mapper.BaseBehaviormanagementLogMapper;
import com.ruoyi.service.IBaseBehaviormanagementLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 行为管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-28
 */
@Service
public class BaseBehaviormanagementLogServiceImpl implements IBaseBehaviormanagementLogService 
{
    @Autowired
    private BaseBehaviormanagementLogMapper baseBehaviormanagementLogMapper;

    /**
     * 查询行为管理
     * 
     * @param id 行为管理主键
     * @return 行为管理
     */
    @Override
    public BaseBehaviormanagementLog selectBaseBehaviormanagementLogById(Long id)
    {
        return baseBehaviormanagementLogMapper.selectBaseBehaviormanagementLogById(id);
    }

    /**
     * 查询行为管理列表
     * 
     * @param baseBehaviormanagementLog 行为管理
     * @return 行为管理
     */
    @Override
    public List<BaseBehaviormanagementLog> selectBaseBehaviormanagementLogList(BaseBehaviormanagementLog baseBehaviormanagementLog)
    {
        return baseBehaviormanagementLogMapper.selectBaseBehaviormanagementLogList(baseBehaviormanagementLog);
    }

    /**
     * 新增行为管理
     * 
     * @param baseBehaviormanagementLog 行为管理
     * @return 结果
     */
    @Override
    public int insertBaseBehaviormanagementLog(BaseBehaviormanagementLog baseBehaviormanagementLog)
    {
        //通过用户 ID 找设备 案例ID
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        String eqName = baseBehaviormanagementLogMapper.equName(sysUser.getUserId(),baseBehaviormanagementLog.getCaseId());
        baseBehaviormanagementLog.setEquipmentName(eqName);
        return baseBehaviormanagementLogMapper.insertBaseBehaviormanagementLog(baseBehaviormanagementLog);
    }

    /**
     * 修改行为管理
     * 
     * @param baseBehaviormanagementLog 行为管理
     * @return 结果
     */
    @Override
    public int updateBaseBehaviormanagementLog(BaseBehaviormanagementLog baseBehaviormanagementLog)
    {
        return baseBehaviormanagementLogMapper.updateBaseBehaviormanagementLog(baseBehaviormanagementLog);
    }

    /**
     * 批量删除行为管理
     * 
     * @param ids 需要删除的行为管理主键
     * @return 结果
     */
    @Override
    public int deleteBaseBehaviormanagementLogByIds(Long[] ids)
    {
        return baseBehaviormanagementLogMapper.deleteBaseBehaviormanagementLogByIds(ids);
    }

    /**
     * 删除行为管理信息
     * 
     * @param id 行为管理主键
     * @return 结果
     */
    @Override
    public int deleteBaseBehaviormanagementLogById(Long id)
    {
        return baseBehaviormanagementLogMapper.deleteBaseBehaviormanagementLogById(id);
    }
}
